﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.Packaging;

namespace OPENXMLLib
{
    public class XSheet
    {
        private WorksheetPart _worksheetPart;
        Sheet _sheet;

        public XSheet(Sheet sheet, WorksheetPart worksheetPart)
        {
            _sheet = sheet;
            _worksheetPart = worksheetPart;
        }

        public XCell GetCell(string cellReference)
        {
            uint rowIndex = GetCellRowIndex(cellReference);
            SheetData sheetData = _worksheetPart.Worksheet.Elements<SheetData>().FirstOrDefault();
            Row row = sheetData.GetRow(rowIndex, false);

            List<Cell> cells = row.Elements<Cell>().ToList();

            Cell cell = row.GetCell(cellReference, false);
            if (cell != null)
            {
                return null;
            }
            return null;
        }

        private uint GetCellRowIndex(string cellReference)
        {
            string value = Convert.ToString(cellReference);

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\d+");
            System.Text.RegularExpressions.Match match = regex.Match(value);
            return uint.Parse(match.Value);
        }
    }
}
